package org.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        // 1. 创建Spring IOC容器
        ApplicationContext context =
                new ClassPathXmlApplicationContext("applicationContext.xml");

        // 2. 从容器中获取Product bean
        Product product = (Product) context.getBean("product");
        System.out.println("Product Bean: " + product);

        // 3. 从容器中获取Student bean
        Student student = (Student) context.getBean("student");
        System.out.println("Student Bean: " + student);

        // 4. 也可以使用类型获取bean
        Product productByType = context.getBean(Product.class);
        Student studentByType = context.getBean(Student.class);

        System.out.println("Product by type: " + productByType);
        System.out.println("Student by type: " + studentByType);

        // 5. 验证是否是同一个实例（单例模式）
        System.out.println("Product instances are same: " + (product == productByType));
        System.out.println("Student instances are same: " + (student == studentByType));
    }
}
